package com.wut.clock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.wut.clock.entity.ArticleTag;
import com.wut.clock.mapper.ArticleMapper;
import com.wut.clock.mapper.ArticleTagMapper;
import com.wut.clock.service.IArticleService;
import com.wut.clock.vo.admin.ArticleVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ZYH
 * @unit D9Lab
 * @description 文章实现类
 * @date 2022/5/31 20:55
 */
@Service
@RequiredArgsConstructor
public class ArticleServiceImpl implements IArticleService {

    private final ArticleMapper articleMapper;

    private final ArticleTagMapper articleTagMapper;

    @Transactional
    @Override
    public int deleteArticle(Integer articleId) {
        // 删除文章对应的标签记录
        articleTagMapper.delete(new QueryWrapper<ArticleTag>().eq("article_id",articleId));
        //删除文章的评论

        return articleMapper.deleteById(articleId);
    }

    @Override
    public List<ArticleVo> getArticleList(Integer pageNum, Integer pageSize, Integer userId, Integer categoryId, String articleTitle, Integer status, Integer verifyStatus) {
        PageHelper.startPage(pageNum,pageSize);
        return articleMapper.getArticleList(userId,categoryId,articleTitle,status,verifyStatus);
    }

    @Override
    public ArticleVo getArticleDetail(Integer articleId) {
        return articleMapper.getArticleDetail(articleId);
    }
}
